package cn.zhuama.basic.sevice.impl;

import cn.zhuama.basic.mapper.BaseMapper;
import cn.zhuama.basic.query.BaseQuery;
import cn.zhuama.basic.sevice.IBaseService;
import cn.zhuama.basic.util.PageList;
import cn.zhuama.org.domain.Department;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    BaseMapper<T> baseMapper;

    @Override
    public List<T> findAll() {
        return baseMapper.loadAll();
    }

    @Override
    public PageList<T> queryPage(BaseQuery query) {
        Long count = baseMapper.queryCount(query);
        if(count<1){
            return new PageList<T>();
        }else {
            List<T> Ts = baseMapper.queryData(query);
            return new PageList<T>(count,Ts);
        }
    }

    @Override
    @Transactional
    public void add(T T) {
        baseMapper.save(T);
    }

    @Override
    @Transactional
    public void update(T T) {
        baseMapper.update(T);
    }

    @Override
    public T queryOne(Long id) {
            return baseMapper.queryOne(id);
    }

    @Override
    @Transactional
    public void del(Long id) {
        baseMapper.del(id);
    }

    @Override
    public void patchDel(List<Long> ids) {
        baseMapper.patchDel(ids);
    }
}
